package cn.itcast.myapplication.viewemodel;

import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;

public class NavViewModel extends ViewModel {

    public MutableLiveData<Integer> number;//数量

    //获取数量
    public MutableLiveData<Integer> getNumber() {

        //如果数量等于空，那么就去创建，设置值为零
        if (number==null){

            number=new MutableLiveData<>();

            number.setValue(0);

        }

        return number;

    }



    public void add(int x){

        number.setValue(number.getValue()+x);

        if (number.getValue()<0){

            number.setValue(0);

        }

    }

}
